<!-- eslint-disable vue/multi-word-component-names -->
<template>
  <div class="shebeiguanli">
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="设备编号">
        <el-input
          v-model.trim="formInline.innerCode"
          placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="sbSearch">查询</el-button>
        <el-button type="success" icon="el-icon-search" @click="sbReset">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="dw-bottom">
      <!-- <div class="dw-add">
        <el-button
          type="primary"
          icon="el-icon-circle-plus-outline"
          @click.native="addSb"
          >新建</el-button
        >
        <el-button @click.native="addHzs">批量操作</el-button>
      </div> -->
      <!-- 列表区域 -->
      <div class="dw-content">
        <el-table :data="ShjList" style="width: 100%" tooltip-effect="dark"  v-loading="loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    >
          <el-table-column type="selection" width="80"> </el-table-column>
          <el-table-column prop="num" label="序号" width="100" type="index">
          </el-table-column>
          <el-table-column prop="innerCode" label="设备编号" width="150">
          </el-table-column>
          <el-table-column prop="type[name]" label="设备型号" width="150">
          </el-table-column>
          <el-table-column prop="node[addr]" label="详细地址" width="200">
          </el-table-column>
          <el-table-column prop="ownerName" label="合作商" width="150">
          </el-table-column>
          <el-table-column prop="vmStatus" label="设备状态" width="130" :formatter='formaAter'>
          </el-table-column>
          <el-table-column prop="labor" label="操作" class="caozuo">
            <template>
              <span>货道</span>
              <span>策略</span>
              <span>修改</span>
            </template>
          </el-table-column>
        </el-table>
        <div class="dw-footer">
          <!-- 页码 -->
          <Page
            :total="Number(totalCount)"
            :totalPage="Number(totalPage)"
            :page.sync="data.pageIndex"
            @gengxin="getShjList"
          ></Page>
        </div>
        <!-- 新增 -->
        <SbglXz :sbglVisible.sync = sbglVisible></SbglXz>
      </div>
    </div>
  </div>
</template>

<script>
import SbglXz from './components/sbglXz.vue'
import Page from '../dianweiguanli/components/Page.vue'
import { getShj } from '@/api/shebeiguanli/shebeiguanli'
export default {
  components: {
    Page,
    SbglXz
  },
  data () {
    return {
      sbglVisible: false,
      loading: false,
      hzsXqVisible: false,
      hzsShow: false,
      hzsVisible: false,
      formInline: {
        innerCode: ''
      },
      ShjList: [],
      data: {
        pageIndex: 1,
        pageSize: 10
      },
      totalCount: 0, // 总量
      totalPage: 0 // 总页数
    }
  },
  created () {
    this.getShjList()
  },
  mounted () {},
  methods: {
    async getShjList () {
      this.loading = true
      const { data } = await getShj(this.data)
      this.ShjList = data.currentPageRecords
      // 处理详细地址
      this.ShjList.forEach(item => {
        item.node.addr = item.node.addr.split('-').reverse().splice(0, 1).join('')
      })
      this.totalCount = data.totalCount
      this.totalPage = data.totalPage
      this.loading = false
    },
    // 处理设备状态数据
    formaAter (row, column, cellValue, index) {
      // console.log('cellValue :>> ', cellValue)
      if (cellValue === 0) return '未投放'
      if (cellValue === 1) return '运营'
      if (cellValue === 3) return '撤机'
    },
    // 设备编号搜索
    async sbSearch () {
      const { data } = await getShj({ ...this.data, ...this.formInline })
      this.ShjList = data.currentPageRecords
      this.ShjList.forEach(item => {
        item.node.addr = item.node.addr.split('-').reverse().splice(0, 1).join('')
      })
      this.totalCount = data.totalCount
      this.totalPage = data.totalPage
      this.loading = false
    },
    // 重置
    sbReset () {
      this.getShjList()
      this.formInline = {
        innerCode: ''
      }
    },
    // 新增设备
    addSb () {
      this.sbglVisible = true
    }
  }
}
</script>
<style lang="less" scoped>
.shebeiguanli {
  * {
    box-sizing: border-box;
  }
  padding: 80px 20px 20px;
  background-color: #f8fafd;

  .dw-bottom {
    padding-left: 17px;
    padding-top: 20px;
    width: 1185px;
    height: 673px;
    background-color: #fff;
    .dw-add {
      margin-bottom: 20px;
      width: 1153px;
      height: 36px;
      .el-button--primary {
        // display: inline-block;
        cursor: pointer;
        width: 80px;
        height: 36px;
        color: #fff;
        font-size: 14px;
        background-color: #ff6726;
        border-color: #ff6726;
        padding: 0;
      }
      .el-button--default {
        width: 80px !important;
        height: 36px;
        padding: 0;
        color: #655b56 !important;
        background-color: #fbf4f0 !important;
        border-color: #fbf4f0;
      }
    }
    .dw-content {
      /deep/.el-table th {
        background-color: #f3f6fb;
      }
      span {
        margin-right: 10px;
        cursor: pointer;
        font-size: 14px;
        color: #5f84ff;
      }
      .dw-footer {
        display: flex;
        justify-content: space-between;
        padding: 32px 16px;
        width: 1153px;
        height: 96px;
        p {
          font-size: 16px;
          color: #606266;
        }
        .btn {
          .btn1,
          .btn2 {
            // display: flex;
            background-color: #d5ddf8;
            width: 70px;
            height: 32px;
            margin: 0 16px;
            padding: 0;
          }
        }
      }
    }
  }
}
</style>
